package com.ruiysoft.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruiysoft.crm.model.entity.BizCarInfo;
import com.ruiysoft.crm.service.BizCarInfoService;
import com.ruiysoft.crm.model.vo.Response;
import com.ruiysoft.crm.util.Query;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author fanyl
 */
@Api(tags = "车辆信息")
@RestController
@RequestMapping("/car")
public class BizCarInfoController {

    @Autowired
    private BizCarInfoService bizCarinfoService;

    /**
     * 通过ID查询信息
     *
     * @param id ID
     * @return
     */
    @GetMapping("/get/{id}")
    public BizCarInfo get(@PathVariable Integer id) {
        return bizCarinfoService.getById(id);
    }

    /**
     * 分页查询
     *
     * @param params 分页对象
     * @return 分页对象
     */
    @GetMapping("/list/page")
    public IPage dictPage(@RequestParam Map<String, Object> params) {
        return bizCarinfoService.page(new Query<>(params), new QueryWrapper<>());
    }

    /**
     * 添加
     *
     * @param bizCarInfo 车辆信息
     * @return success、false
     */
    @PostMapping("/insert")
    public Response add(@RequestBody BizCarInfo bizCarInfo) {
        bizCarInfo.setCreateDate(LocalDateTime.now());
        return Response.success(bizCarinfoService.save(bizCarInfo));
    }

    /**
     * 删除
     *
     * @param id ID
     * @return R
     */
    @DeleteMapping("/delete/{id}")
    public Response delete(@PathVariable Integer id) {
        return Response.success(bizCarinfoService.removeById(id));
    }

    /**
     * 修改
     *
     * @param bizCarinfo
     * @return success/false
     */
    @PutMapping("/update")
    public Response editDict(@RequestBody BizCarInfo bizCarinfo) {
        bizCarinfo.setModificationDate(LocalDateTime.now());
        return Response.success(bizCarinfoService.updateById(bizCarinfo));
    }
}
